package com.xg.te.strategy;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.xg.te.core.WebsiteStore;
import com.xg.te.core.PageStore;
import com.xg.te.core.bean.WebsiteBean;
import com.xg.te.core.bean.PageBean;

/**
 * @desc 修改状态策略
 * @author liuguojun
 * @date 2014-07-16
 */
public class FileModifiedStrategy extends Strategy {

	private Map<String, Long> moniter = new HashMap<String, Long>();

	public void execute(JSONObject jsonObj) {
		try {
			for (Iterator<String> it = pages.iterator(); it.hasNext();) {
				String pageCode = it.next();
				Long mt = moniter.get(pageCode);

				String[] arr = pageCode.split("_");
				if (arr.length != 2) {
					continue;
				}

				WebsiteBean ab = WebsiteStore.get(arr[0]);
				PageBean pb = PageStore.get(arr[1]);
				String tempPath = ab.getConstantValue("tempPath");
				File file = new File(tempPath + File.separator + pb.getTpath());
				Long ft = file.lastModified();

				if (mt == null || ft > mt) {
					staticHtml(arr[0], arr[1]);
					moniter.put(pageCode, ft);
				}
			}
		} catch (Exception ex) {
			logger.error(ex.getMessage(), ex);
		}
	}

}
